﻿
@{
    Layout = null;
}

<link href="~/libs/layui-v2.9.21/layui/css/layui.css" rel="stylesheet" />

<style>
    .layui-form-label {
        width: 160px
    }

    .layui-input-block {
        margin-left: 200px;
    }

    .layui-form-item {
        margin-bottom: 30px; /* 每个行之间的距离 */
        width: 480px
    }

</style>
<form class="layui-form" action="">
    <table>
		<tr>
			<td>
                <div class="layui-form-item">
                    <label class="layui-form-label">创建人名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="CreateName" lay-verify="required" placeholder="请输入创建人名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">创建日期</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" name="CreateDate" id="ID-laydate-demo" placeholder="yyyy-MM-dd" class="layui-input">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">到货通知单</label>
                    <div class="layui-input-block">
                        <input type="text" name="ArrivalNotice" lay-verify="required" placeholder="请输入到货通知单" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">客户订单号</label>
                    <div class="layui-input-block">
                        <input type="text" name="CustomerOrderNumber" lay-verify="required" placeholder="请输入客户订单号" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <input type="text" name="Remarks" lay-verify="required" placeholder="备注" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">商品编码</label>
                    <div class="layui-input-block">
                        <input type="text" name="ProductCode" lay-verify="required" placeholder="请输入商品编码" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">商品名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="ProductName" lay-verify="required" placeholder="请输入商品名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">预约数量</label>
                    <div class="layui-input-block">
                        <input type="text" name="ScheduledQuantity" lay-verify="required" placeholder="请输入预约数量" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            
        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">已登记数量</label>
                    <div class="layui-input-block">
                        <input type="text" name="RegisteredQuantity" lay-verify="required" placeholder="请输入已登记数量" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">未收货数量</label>
                    <div class="layui-input-block">
                        <input type="text" name="UnreceivedQuantity" lay-verify="required" placeholder="请输入未收货数量" autocomplete="off"  class="layui-input">
                    </div>
                </div>
            </td>
            
        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">生产日期</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" name="ProductionDate" id="ID-laydate-demo" placeholder="yyyy-MM-dd" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">批次</label>
                    <div class="layui-input-block">
                        <input type="text" name="BatchNumber" lay-verify="required" placeholder="请输入批次" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            
        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">储位</label>
                    <div class="layui-input-block">
                        <input type="text" name="StorageLocation" lay-verify="required" placeholder="请输入储位" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">托盘</label>
                    <div class="layui-input-block">
                        <input type="text" name="PalletNumber" lay-verify="required" placeholder="请输入托盘" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            
        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label">单位</label>
                    <div class="layui-input-block">
                        <input type="text" name="Unit" lay-verify="required" placeholder="请输入单位" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="submit" class="layui-btn" lay-submit lay-filter="add">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        <button type="button" class="layui-btn layui-btn-primary" onclick="closeWorkstation()">返回</button>
                    </div>
                </div>
            </td>
        </tr>
    </table>
</form>

<script src="~/libs/jquery/jquery.js"></script>
<script src="~/libs/layui-v2.9.21/layui/layui.js"></script>

<script>

    //关闭弹框
    function closeWorkstation() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }

    layui.use(['form', 'laydate', 'util'], function () {
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var util = layui.util;

        laydate.render({
            elem: '#ID-laydate-demo'
        });

        // 提交事件
        form.on('submit(add)', function (data) {
            var field = data.field;

            console.log(field);
            $.ajax({
                url: '/BatchReceiving/AddBatchReceiving',
                type: 'POST',
                data: field,
                dataType: 'json',
                success: function (res) {
                    if (res == 0) {
                        layer.alert('添加成功', { title: '操作结果' }, function () {
                            layer.closeAll();
                            closeWorkstation()
                        });
                    } else {
                        layer.alert('添加失败：' + res.msg, { title: '操作结果' });
                    }
                },
                error: function (err) {
                    // 处理添加失败的情况
                    layer.alert('添加失败：网络异常，请稍后重试', { title: '操作结果' });
                    console.error('添加失败', err);
                }
            });

            return false; // 阻止默认 form 提交
        });
    });
</script>